import 'package:flutter/material.dart';
import 'package:mobile_app.core/core/presentation/theme/styles.dart';

part 'styles.dart';

part 'text_theme.dart';

class IntroPageTheme extends InheritedTheme {
  IntroPageTheme({
    required Brightness brightness,
    required super.child,
    super.key,
  })  : _brightness = brightness,
        _data = _buildThemeData(
          brightness: brightness,
        );

  final Brightness _brightness;
  final IntroPageThemeData _data;

  static IntroPageThemeData _buildThemeData({
    required Brightness brightness,
  }) {
    return switch (brightness) {
      Brightness.dark => IntroPageThemeData.dark(),
      Brightness.light => IntroPageThemeData.light(),
    };
  }

  static IntroPageThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<IntroPageTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<IntroPageTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return IntroPageTheme(
      brightness: _brightness,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(IntroPageTheme oldWidget) {
    return _brightness != oldWidget._brightness;
  }
}

class IntroPageThemeData {
  const IntroPageThemeData._internal({
    required this.imageBackgroundColor,
    required this.backgroundColor,
    required this.imageFloorColor,
    required this.textTheme,
  });

  factory IntroPageThemeData.light() {
    return IntroPageThemeData._internal(
      imageBackgroundColor: IntroPageStyles.imageBackgroundColorLight,
      backgroundColor: Colors.white,
      imageFloorColor: IntroPageStyles.imageFloorColorLight,
      textTheme: IntroPageTextTheme.light(),
    );
  }

  factory IntroPageThemeData.dark() {
    return IntroPageThemeData._internal(
      imageBackgroundColor: IntroPageStyles.imageBackgroundColorDark,
      backgroundColor: CoreStyles.darkGrey4,
      imageFloorColor: IntroPageStyles.imageFloorColorDark,
      textTheme: IntroPageTextTheme.dark(),
    );
  }

  final Color imageBackgroundColor;
  final Color backgroundColor;
  final Color imageFloorColor;
  final IntroPageTextTheme textTheme;
}
